﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐
    //
    // 文件名：PasswordUpdate.cs
    // 文件功能描述：修改密码
    // 创建标识：吕海乐2009-05-13
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model.Enum;
using HZ.Supervise;

public partial class PasswordUpdate : BasePage
{
    public PasswordUpdate()
    {
    }
    IBLL_User iu = BLLFactory.BLL_User();
    KeyOperationLogJG kj; 
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnComfirmPwd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strOrigPwd = this.txtOriPwd.Text.Trim();
            string strNewPwd = this.txtNewPwd.Text.Trim();
            string strConfirmPwd = this.txtComfirmNewPwd.Text.Trim();

            //通过session获取用户的ID
            User user = CurrentAccount.GetUser();
            string userId = user.UserID;

            //判断原密码是否正确,保存新密码
            IBLL_User iu = HZ.Supervise.BLLFactory.BLL_User();
            int flag = iu.UpdatePassword(userId, strOrigPwd, strNewPwd);
            switch (flag)
            {
                case 0:
                    PageError("密码更新失败！", Request.RawUrl);
                    break;
                case 1:
                    AddLog(string.Format("密码更新成功!"));
                    PageInfo("密码更新成功！", Request.RawUrl); 
                    txtOriPwd.Text = "";
                    txtNewPwd.Text = "";
                    txtComfirmNewPwd.Text = "";
                    break;
                case 2:
                    PageError("原密码错误！", Request.RawUrl);
                    break;
                default:
                    break;
            }
        }
    }
    /// <summary>
    /// 添加日志
    /// </summary>
    /// <param name="msg"></param>
    private void AddLog(string msg)
    {
        kj = new KeyOperationLogJG();
        kj.OperationLogSerialID = Guid.NewGuid().ToString();
        kj.Operator = CurrentAccount.GetUser().UserID;
        kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
        kj.OperateTime = DateTime.Now;
        kj.OperateMessage = msg;
        iu.AddKeyOperationLog(kj);
    }
}

